package org.weishe.fof;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class FOFMapper extends Mapper<Text, Text, FOF, IntWritable> {
	private IntWritable one = new IntWritable(1);
	private IntWritable two = new IntWritable(2);

	@Override
	protected void map(Text key, Text value, Mapper<Text, Text, FOF, IntWritable>.Context context)
			throws IOException, InterruptedException {
		String line = value.toString();
		String[] fs = line.split("\t");
		// 设置直接好友
		for (String f : fs) {
			context.write(new FOF(key.toString(), f), two);
		}

		// 设置间接好友
		for (int i = 0; i < fs.length; i++) {

			if (i + 1 == fs.length) {
				return;
			}
			for (int j = i + 1; j < fs.length; j++) {
				FOF fof = new FOF(fs[i], fs[j]);
				context.write(fof, one);
			}
		}

	}

}
